package com.hoopchina.ui.main;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;

/**
 * UIWidget
 * UI widget抽象类
 * 
 * @author Neusoft
 */
public abstract class UIWidget extends LinearLayout {
	protected Context                mContext;  // reference to parent
	protected IWidgetEventListener   mListener; // now support only one event listener

	/**
	 * 构造器
	 */
	public UIWidget( Context context ) {
		super( context );
		mContext = context;
		loadResources();
	}
	
	/**
	 * 构造器
	 */
	public UIWidget( Context context, AttributeSet attrs ) {
		super( context, attrs );
		mContext = context;
		loadResources();
	}
	
	/**
	 * 设置控件事件监听
	 */
	public void setListener( IWidgetEventListener aListener ) {
		mListener = aListener;
	}
	
	/**
	 * 移除监听器
	 */
	public void removeListener() {
		mListener = null;
	}
	
	/**
	 * 把事件通知给监听器
	 */
	protected void notifyEvent( Object aData ) {
		if ( mListener != null ) {
			mListener.onEventOccured( new WidgetEventArgs( this, aData ) );
		}
	}
	
	/**
	 * 加载资源
	 */
	protected abstract void loadResources();

}
